package org.ligson.busdemo1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/demo1")
public class DemoController {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private BusProperties busProperties;

    @GetMapping("/sendmsg")
    public String sendMsg(String name) {
        LogEvent logEvent = new LogEvent(this, busProperties.getId(), "**");
        logEvent.setName(name);
        applicationContext.publishEvent(logEvent);
        return name;
    }
}
